package com.example.warehouse.bus.dao.persist.repository.impl;

import com.example.warehouse.bus.dao.persist.mapper.BusOutportMapper;
import com.example.warehouse.bus.dao.persist.repository.IBusOutportRepository;
import com.example.warehouse.bus.pojo.entity.BusOutport;
import com.example.warehouse.bus.pojo.param.BusOutportUpdateParam;
import com.example.warehouse.bus.pojo.vo.BusInportListItemVO;
import com.example.warehouse.bus.pojo.vo.BusOutportListItemVO;
import com.example.warehouse.common.pojo.vo.PageData;
import com.example.warehouse.common.security.CurrentPrincipal;
import com.example.warehouse.common.util.PageInfoToPageDataConverter;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author XXH
 * @Date 2023/7/15 23:33
 * @Version 1.0
 */
@Slf4j
@Repository
public class IBusOutportRepositoryImpl implements IBusOutportRepository {

    @Autowired
    BusOutportMapper busOutportMapper;


    /**
     * 新增退货数据
     *
     * @param busOutport
     * @return 插入条目数量
     */
    @Override
    public int insert(BusOutport busOutport) {
        log.debug("新增退货,repository,参数:退货实体类:{}", busOutport);
        Integer row = busOutportMapper.insert(busOutport);
        return row;
    }

    /**
     * 根据id删除退货数据
     * @param id
     * @param currentPrincipal
     * @return 受影响条目数
     */
    @Override
    public int deleteById(Long id,CurrentPrincipal currentPrincipal) {
        log.debug("新增退货,repository,参数:id:{},最近当事人:{}",id, currentPrincipal);
        return busOutportMapper.deleteById(id,currentPrincipal);
    }

    /**
     * 根据id修改退货数据
     * @param id
     * @param busOutportUpdateParam
     * @return
     */
    @Override
    public int updateById(Long id, BusOutportUpdateParam busOutportUpdateParam) {
        log.debug("修改退货,repository,参数:id:{},最近当事人:{}",id, busOutportUpdateParam);
        return busOutportMapper.updateById(id,busOutportUpdateParam);
    }

    /**
     * 查询退货(Outport)列表--查
     * @param pageNum 页码
     * @param pageSize 每页记录数
     * @return
     */
    @Override
    public PageData<BusOutportListItemVO> list(Integer pageNum, Integer pageSize) {
        log.debug("查询退货,repository,参数:页码:{},每页记录数:{}",pageNum, pageSize);
        PageHelper.startPage(pageNum,pageSize);
        List<BusOutportListItemVO> list= busOutportMapper.list();
        PageInfo<BusOutportListItemVO> pageInfo=new PageInfo<>(list);
        PageData<BusOutportListItemVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }


    @Override
    public List<BusOutport> selectAllOut() {
        List<BusOutport> list = busOutportMapper.selectList(null);
        return list;

    }
}
